<?php
header ( 'content-type:text/html; charset=utf-8' );
@$login = $_REQUEST ['login'];
@$password = $_REQUEST ['password'];


@$message = "";
if (empty ( $login ) || empty ( $password )) {
	$message = "登录信息不完整";
} else {
	$pdo = new PDO ( 'mysql:dbname=shu', 'root' );
	$s = $pdo->prepare ( 'select id,password from yazi where login=:login' );
	$s->execute ( array (
			'login' => $login 
	));
	
	$user = $s->fetch ( PDO::FETCH_NAMED );
	if (empty ( $user )) {
		$message = "用户名不存在";
	}else{
		if ($user ['password'] != $password) {
			$message = "密码错误";
		} else {
			unset ( $user ['password'] );
			$user ['login'] = $login;
			session_start ();
			$_SESSION ['yazi'] = $user;
			$message = "登录成功";
			header ( 'Refresh:2;url=/th2.php' );
		}
	}
}

?>

<!DOCTYPE html>
<html>
<head>
<title>登录页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
	charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
         <script src="js/html5shiv.js"></script>
         <script src="js/respond.min.js"></script>
      <![endif]-->
</head>
<style type="text/css">
body{ padding-top:70px; }
</style>
<body>
	<div class="container">
		<div class="row">
			<div class="col-xs-3"></div>
			<div class="col-xs-6">
				<div class="alert alert-danger"><?php echo $message;?> <a
						class="close" data-dismiss="alert">&times;</a>
				</div>
				<div class="modal-content">
					<div class="modal-header">
						<div class="modal-title">
							<h3>-欢迎来到本网站，请登录-</h3>
						</div>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" action="login.php" method="post">
							<div class="form-group">
								<label class="col-xs-3 control-label">登录名:</label>
								<div class="col-xs-9">
									<div class="input-group">
										<div class="input-group-addon">
											<span class="glyphicon glyphicon-user"></span>
										</div>
										<input class="form-control" placeholder="用户名" name="login" />
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-3 control-label">密码:</label>
								<div class="col-xs-9">
									<div class="input-group">
										<div class="input-group-addon">
											<span class="glyphicon glyphicon-eye-open"></span>
										</div>
										<input class="form-control" placeholder="密码" name="password" />
									</div>
								</div>
							</div>
							<div class="button text-right">
								<button class="btn btn-default" type="submit">登录</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="col-xs-3"></div>
</body>
</html>
